<template>
  <div class="zjhistory">
    <div class="title">
      <img
        src="../../assets/images/cz1.png"
        alt=""
        class="goback"
        @click="goback"
      />
      {{ active == 0 ? $t("long.tip_zijinfeilv2") : $t("long.fengxianbzj") }}
    </div>
    <div class="topwai">
      <div class="top" @click="cens">
        <p>{{ $t("common.heyue") }}</p>
        <p>
          {{ currentName }} {{ $t("common.yongxu") }}
          <img src="../../assets/images/xia.png" alt="" />
        </p>
      </div>
      <div class="center" v-show="cen">
        <van-search
          v-model="valuesearch"
          :placeholder="$t('long.qingshuruguanjianci')"
        />
        <div class="p">
          <p
            v-for="item in allOSList"
            :key="item.symbolId"
            @click="chooseItem(item)"
          >
            {{ item.symbolName }}{{ $t("common.yongxu") }}
          </p>
        </div>
      </div>
    </div>
    <div class="bottom">
      <van-tabs v-model="active" swipeable>
        <van-tab :title="$t('long.tip_zijinfeilv2')">
          <van-list
            v-model="loading"
            :finished="finished"
            :finished-text="$t('long.meiyougengduo')"
            @load="getFundRateList"
          >
            <div class="list" v-for="item in list" :key="item.id">
              <div class="listd1">{{ item.createTime }}</div>
              <div class="listd2">
                <p>{{ $t("long.zijinfeilvjiange") }}</p>
                <p>{{ item.fundingRateInterval }}{{ $t("long.xiaoshi") }}</p>
              </div>
              <div class="listd2">
                <p>{{ $t("long.zijinfeilvdjs") }}</p>
                <p>{{ +item.fundingRate }}%</p>
              </div>
            </div>
          </van-list>
        </van-tab>
        <van-tab :title="$t('long.fengxianbzj')">
          <van-list
            v-model="loading"
            :finished="finished"
            :finished-text="$t('long.meiyougengduo')"
            @load="getFundRateList2"
          >
            <div class="list" v-for="item in list2" :key="item.id">
              <div class="listd1">{{ item.createTime }}</div>
              <div class="listd2">
                <p>{{ $t("long.fengxianbzj2") }}(USDT)</p>
                <p>{{ $formatMoney(item.cost, 2) }}</p>
              </div>
            </div>
          </van-list>
        </van-tab>
      </van-tabs>
    </div>
    <div class="hei" v-show="cen" @click="censf"></div>
  </div>
</template>
<script>
export default {
  name: "zjhistory",
  data() {
    return {
      active: 0,
      currentName: "",
      oldOSList: [],
      allOSList: [],
      symbolId: "1",
      page: 1,
      loading: false,
      finished: false,
      list: [],
      list2: [],

      valuesearch: "",
      cen: false,
    };
  },
  watch: {
    active(val) {
      this.page = 1;
      if (val == 0) {
        this.getFundRateList();
      } else {
        this.getFundRateList2();
      }
    },
    valuesearch(val) {
      this.allOSList = this.oldOSList.filter((v) =>
        v.symbolName.includes(val.toUpperCase())
      );
    },
  },
  computed: {},
  created() {},
  activated() {
    this.symbolId = this.$route.query.symbolId;
    this.active = +this.$route.query.index;
    this.getOptionSymbolList();
  },
  methods: {
    chooseItem(item) {
      this.symbolId = item.symbolId;
      this.currentName = item.symbolName;
      this.cen = false;
      this.page = 1;
      if (this.active == 0) {
        this.getFundRateList();
      } else {
        this.getFundRateList2();
      }
    },
    async getOptionSymbolList() {
      this.valuesearch = "";
      const ret = await this.$http({
        url: "/contract/contractOptionalSymbol/list",
        method: "post",
        data: {
          orderName: 0, //名称排序 0 升序 1 降序  null 不排序
          orderSumPrice: 1, //成交量排序 0 升序 1 降序  null 不排序
          orderLastPrice: null, //最新价排序 0 升序 1 降序  null 不排序
          orderRiseAndFallRange: null, //涨跌幅排序 0 升序 1 降序  null 不排序
          type: "all", //查询类型  是否查询当前登陆人所选的币对 ，false -> 查全部
        },
      });
      if (ret.data.code === 0) {
        this.oldOSList = ret.data.data;
        this.allOSList = ret.data.data;
        this.currentName =
          this.allOSList.find((v) => v.symbolId == this.symbolId).symbolName ||
          "";
        this.cen = false;
      }
    },
    async getFundRateList2() {
      const ret = await this.$http({
        url: "/wallet/liquidationExpensesStatistics/page",
        method: "get",
        params: {
          current: this.page,
          size: 50,
          symbolId: this.symbolId,
        },
      });
      if (ret.data.code === 0) {
        this.loading = false;
        if (this.page == 1) {
          this.list2 = ret.data.data.records || [];
        } else {
          this.list2 = this.list.concat(ret.data.data.records || []);
        }
        this.page++;
        if (this.list2.length >= +ret.data.data.total) {
          this.finished = true;
        }
      }
    },
    async getFundRateList() {
      const ret = await this.$http({
        url: "/contract/rippleContractFundingRateHistory/page",
        method: "get",
        params: {
          current: this.page,
          size: 50,
          symbolId: this.symbolId,
        },
      });
      if (ret.data.code === 0) {
        this.loading = false;
        if (this.page == 1) {
          this.list = ret.data.data.records || [];
        } else {
          this.list = this.list.concat(ret.data.data.records || []);
        }
        this.page++;
        if (this.list.length >= +ret.data.data.total) {
          this.finished = true;
        }
      }
    },
    goback() {
      this.$router.go("-1");
    },
    cens() {
      if (this.cen === true) {
        this.cen = false;
      } else if (this.cen === false) {
        this.cen = true;
      }
    },
    censf() {
      this.cen = false;
    },
  },
};
</script>
<style lang="scss" scoped>
.zjhistory {
  font-size: 3.2vw;
  .title {
    font-size: 4.8vw;
    line-height: 44px;
    background-color: #090A1B;
    color: rgba(255, 255, 255, 100);
    text-align: center;
    //font-family: Arial;
    margin-bottom: 2vw;
    .img {
      position: absolute;
      top: 3.6vw;
      right: 4vw;
      display: flex;
      justify-content: space-between;
      img {
        width: 5vw;
      }
    }
    .goback {
      position: absolute;
      top: 3vw;
      left: 2vw;
      width: 5.33vw;
      height: 5.33vw;
    }
  }
  .topwai {
    position: relative;
    margin-bottom: 4.2vw;
    margin-left: 4.2vw;
    margin-top: 5.8vw;
    z-index: 10;
    .top {
      width: 60.2vw;
      height: 8.8vw;
      box-sizing: border-box;
      // border: 0.2vw solid #8992AE;
      background-color: #171A2B;
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 0 2.1vw 0 4.2vw;
      border-radius: 3px;
      // p {
      //   position: relative;
      //   top: 0.4vw;
      // }
      img {
        width: 2.6vw;
        position: relative;
        top: -0.2vw;
      }
    }
    .center {
      position: absolute;
      top: 8.8vw;
      width: 60.2vw;
      // height: 40vw;
      background-color: #171A2B;
      ::v-deep .van-search {
        padding: 0;
        width: 60.2vw;
        .van-search__content {
          background-color: #171A2B;
        }
        .van-icon-search {
          color: #fff;
        }
        .van-field__control {
          color: #fff;
        }
        .van-field__clear {
          display: none;
        }
      }
      .p {
        overflow: auto;
        height: 46vw;
        p {
          text-align: left;
          margin-left: 12px;
          line-height: 8vw;
        }
      }
    }
  }
  .bottom {
    .list {
      text-align: left;
      border-top: 0.2vw solid #171A2B;
      padding: 4.2vw 4.2vw 0vw 4.2vw;
      font-size: 3.7vw;
      color: #fff;
      .listd1 {
        margin-bottom: 6.4vw;
      }
      .listd2 {
        margin-bottom: 4.2vw;
        display: flex;
        justify-content: space-between;
        p:first-child {
          color: #8992AE;
        }
      }
    }
  }
  .hei {
    width: 100vw;
    height: 100vh;
    position: fixed;
    top: 44px;
  }
}
.van-tabs {
  min-height: calc(100vh - 21vw);
}
.van-tabs {
  color: #8992AE;
  min-height: 100vh;
  background-color: #090A1B;
  // top: -2vw;
  ::v-deep .van-tabs__wrap {
    // width: 100vw;
    height: 7.4vw;
    // position: fixed;
    // top: 44px;
    // z-index: 10;
    padding-top: 2vw;
    background-color: #090A1B;
    border-bottom: 1px solid #333540;
  }
  // ::v-deep .van-tabs__track{
  //   transform: none !important;
  // }
  ::v-deep .van-tabs__nav--line {
    box-sizing: border-box;
    background-color: #090A1B;
    height: auto;
    // width: 100vw;
  }
  ::v-deep .van-tabs__line {
    width: 4.2vw;
    margin-right: 2vw;
    background-color: #0a7aff;
    bottom: 1.6vw;
  }
  ::v-deep .van-tab {
    border-radius: 5px;
    padding: 0 !important;

    color: #8992AE;
  }
  ::v-deep .van-tab--active {
    color: #fff;
  }
}
</style>
